/*
 * Created by JFormDesigner on Fri Aug 15 20:11:12 CST 2025
 */

package org.xl.main;

import cn.hutool.system.SystemUtil;
import org.xl.main.color.ColorPicker;
import org.xl.main.download.FixedFileDownloader;
import org.xl.main.jenkins.JenkinsDeployFrame;
import org.xl.main.json.JsonFormatFrame;
import org.xl.main.jsonx.JsonToJavaConverter;
import org.xl.main.regex.RegexValidatorFrame;
import org.xl.main.unicode.UniCodeFrame;
import org.xl.main.url.UrlEncoderFrameFrame;
import wjw.cron.ex.MainJFrame;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.Border;

/**
 * @author Windows
 */
public class MainItemFormS extends JFrame {
    public MainItemFormS() {
        initComponents();
    }

    private void jenkinsButtonOk(ActionEvent e) {
        SwingUtilities.invokeLater(() -> {
            JenkinsDeployFrame jenkinsDeployFrame = new JenkinsDeployFrame();
            jenkinsDeployFrame.setSize(1900,800);
            jenkinsDeployFrame.setVisible(true);
            jenkinsDeployFrame.setLocationRelativeTo(null);
            jenkinsDeployFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
        // TODO add your code here
    }

    private void jsonFormatBtnOk(ActionEvent e) {
        SwingUtilities.invokeLater(() -> {
            JsonFormatFrame jsonFormatFrame = new JsonFormatFrame();
            jsonFormatFrame.setSize(1600,800);
            jsonFormatFrame.setVisible(true);
            jsonFormatFrame.setLocationRelativeTo(null);
            jsonFormatFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
        // TODO add your code here
    }

    private void urlButtonOk(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            UrlEncoderFrameFrame urlEncoderFrameFrame = new UrlEncoderFrameFrame();
            urlEncoderFrameFrame.setSize(1600,800);
            urlEncoderFrameFrame.setVisible(true);
            urlEncoderFrameFrame.setLocationRelativeTo(null);
            urlEncoderFrameFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });

    }

    private void cronBtnOk(ActionEvent e) {
        // TODO add your code here
        initCustomLAF();
        SwingUtilities.invokeLater(() -> {
            MainJFrame mainJFrame = new MainJFrame();
            mainJFrame.setVisible(true);
            mainJFrame.setLocationRelativeTo(null);
            mainJFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void initCustomLAF() {
        Font font = new Font("Dialog", 0, 12);
        new Color(5, 50, 156);
        new Color(245, 245, 245);
        Border borderButton = BorderFactory.createEmptyBorder();
        UIManager.put("Button.font", font);
        UIManager.put("ToggleButton.font", font);
        UIManager.put("RadioButton.font", font);
        UIManager.put("CheckBox.font", font);
        UIManager.put("ColorChooser.font", font);
        UIManager.put("ToggleButton.font", font);
        UIManager.put("ComboBox.font", font);
        UIManager.put("ComboBoxItem.font", font);
        UIManager.put("InternalFrame.titleFont", font);
        UIManager.put("Label.font", font);
        UIManager.put("List.font", font);
        UIManager.put("MenuBar.font", font);
        UIManager.put("Menu.font", font);
        UIManager.put("MenuItem.font", font);
        UIManager.put("RadioButtonMenuItem.font", font);
        UIManager.put("CheckBoxMenuItem.font", font);
        UIManager.put("PopupMenu.font", font);
        UIManager.put("OptionPane.font", font);
        UIManager.put("Panel.font", font);
        UIManager.put("ProgressBar.font", font);
        UIManager.put("ScrollPane.font", font);
        UIManager.put("Viewport", font);
        UIManager.put("TabbedPane.font", font);
        UIManager.put("TableHeader.font", font);
        UIManager.put("TextField.font", font);
        UIManager.put("PasswordFiled.font", font);
        UIManager.put("TextArea.font", font);
        UIManager.put("TextPane.font", font);
        UIManager.put("EditorPane.font", font);
        UIManager.put("TitledBorder.font", font);
        UIManager.put("ToolBar.font", font);
        UIManager.put("ToolTip.font", font);
        UIManager.put("Tree.font", font);
        UIManager.put("Table.font", font);
        UIManager.put("Viewport.font", font);
        UIManager.put("Spinner.font", font);
        UIManager.put("PasswordField.font", font);
    }

    private void uniCodeBtnOk(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            UniCodeFrame uniCodeFrame = new UniCodeFrame();
            uniCodeFrame.setSize(1600,800);
            uniCodeFrame.setVisible(true);
            uniCodeFrame.setLocationRelativeTo(null); // 屏幕中央显示
            uniCodeFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void qsBtnOk(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            ColorPicker colorPicker = new ColorPicker();
            colorPicker.setVisible(true);
            colorPicker.setLocationRelativeTo(null); // 屏幕中央显示
            colorPicker.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void commonExportBtnOk(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            String path = FixedFileDownloader.class.getClassLoader().getResource("file/export.zip").getPath();
            String name = SystemUtil.getOsInfo().getName();
            if (name.contains("Windows") || name.contains("windows")) {
                path = path.substring(1);
            }
            FixedFileDownloader fixedFileDownloader = new FixedFileDownloader(path);
            fixedFileDownloader.setVisible(true);
            fixedFileDownloader.setLocationRelativeTo(null); // 屏幕中央显示
            fixedFileDownloader.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void zebtnOk(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception ex) {
            }
            RegexValidatorFrame validator = new RegexValidatorFrame();
            validator.setVisible(true);
            validator.setLocationRelativeTo(null); // 屏幕中央显示
            validator.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void jsonzjavaBtnOk(ActionEvent e) {
        SwingUtilities.invokeLater(() -> {
            JsonToJavaConverter jsonToJavaConverter = new JsonToJavaConverter();
            jsonToJavaConverter.setVisible(true);
            jsonToJavaConverter.setLocationRelativeTo(null); // 屏幕中央显示
            jsonToJavaConverter.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void jetbrainDwBtn(ActionEvent e) {
        // TODO add your code here
        SwingUtilities.invokeLater(() -> {
            String path = FixedFileDownloader.class.getClassLoader().getResource("file/JetBrains.zip").getPath();
            String name = SystemUtil.getOsInfo().getName();
            if (name.contains("Windows") || name.contains("windows")) {
                path = path.substring(1);
            }
            FixedFileDownloader fixedFileDownloader = new FixedFileDownloader(path);
            fixedFileDownloader.setVisible(true);
            fixedFileDownloader.setLocationRelativeTo(null); // 屏幕中央显示
            fixedFileDownloader.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        });
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        button1 = new JButton();
        button2 = new JButton();
        button3 = new JButton();
        button4 = new JButton();
        button5 = new JButton();
        button6 = new JButton();
        button7 = new JButton();
        button8 = new JButton();
        button9 = new JButton();
        button10 = new JButton();

        //======== this ========
        setTitle("\u5de5\u5177\u96c6\u9009\u62e9\u9875");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("Jenkins\u90e8\u7f72");
        button1.addActionListener(e -> jenkinsButtonOk(e));
        contentPane.add(button1);
        button1.setBounds(10, 5, 155, 55);

        //---- button2 ----
        button2.setText("json\u683c\u5f0f\u5316");
        button2.addActionListener(e -> jsonFormatBtnOk(e));
        contentPane.add(button2);
        button2.setBounds(180, 5, 155, 55);

        //---- button3 ----
        button3.setText("url\u7f16\u7801");
        button3.addActionListener(e -> urlButtonOk(e));
        contentPane.add(button3);
        button3.setBounds(350, 5, 155, 55);

        //---- button4 ----
        button4.setText("cron\u8868\u8fbe\u5f0f\u751f\u6210\u5668");
        button4.addActionListener(e -> cronBtnOk(e));
        contentPane.add(button4);
        button4.setBounds(10, 90, 155, 55);

        //---- button5 ----
        button5.setText("Unicode\u7f16\u7801");
        button5.addActionListener(e -> uniCodeBtnOk(e));
        contentPane.add(button5);
        button5.setBounds(185, 90, 155, 55);

        //---- button6 ----
        button6.setText("\u53d6\u8272\u5668");
        button6.addActionListener(e -> qsBtnOk(e));
        contentPane.add(button6);
        button6.setBounds(355, 90, 155, 55);

        //---- button7 ----
        button7.setText("\u901a\u7528\u5bfc\u51fa(\u4f9b\u53c2\u8003)");
        button7.addActionListener(e -> commonExportBtnOk(e));
        contentPane.add(button7);
        button7.setBounds(10, 160, 155, 55);

        //---- button8 ----
        button8.setText("\u6b63\u5219\u8868\u8fbe\u5f0f");
        button8.addActionListener(e -> zebtnOk(e));
        contentPane.add(button8);
        button8.setBounds(185, 160, 155, 55);

        //---- button9 ----
        button9.setText("JSON\u8f6cJAVA");
        button9.addActionListener(e -> jsonzjavaBtnOk(e));
        contentPane.add(button9);
        button9.setBounds(355, 160, 155, 55);

        //---- button10 ----
        button10.setText("jetbrain\u6fc0\u6d3b");
        button10.addActionListener(e -> jetbrainDwBtn(e));
        contentPane.add(button10);
        button10.setBounds(530, 5, 155, 55);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JButton button4;
    private JButton button5;
    private JButton button6;
    private JButton button7;
    private JButton button8;
    private JButton button9;
    private JButton button10;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
